/*javascript only*/
var $_create = function(t,o){
	if(t=='text'){
		var dom = document.createTextNode(o);
	} else if(t=='frag'){
		var dom = document.createDocumentFragment();
	} else {
		if(!t){
			t = 'div';
		}
		var dom = document.createElement(t);
		var keys = Object.keys(o);
		var flen = o.length;
		for(var i=0;i<flen;i++){
			dom.setAttribute(keys[i],o[i]);
		}
	}
	return dom;
};

var $_id = function (var1) {
  return document.getElementById(var1);
};

window.Element.prototype.$_class = function (var1) {
	return this.getElementsByClassName(var1);
};

window.Element.prototype.$_tag = function (var1) {
	return this.getElementsByTagName(var1);
};

window.Element.prototype.before = function(i){
	this.parentElement.insertBefore(i,this);
};

window.Element.prototype.befores = function(is){
	var dom1 = $_create('frag');
	dom1.appendChilds(is);
	this.before(dom1);
};

window.Element.prototype.insertsBefore = function(is,ii){
	var dom1 = $_create('frag');
	dom1.appendChilds(is);
	this.insertBefore(dom1,ii);
};

window.Element.prototype.prependChild = function(i){
	this.insertBefore(i,this.firstChild);
};


window.Element.prototype.prependChilds = function(is){
	var dom1 = $_create('frag');
	dom1.appendChilds(is);
	this.prependChild(dom1);
};

window.Element.prototype.appendChilds = function(is){
	var dom1 = $_create('frag');
	var flen = is.length;
	for(var i=0;i<flen;i++){
		dom1.appendChild(is[i]);
	}
	this.appendChild(dom1);
};

window.Element.prototype.after = function(i){
	var parent = this.parentElement;
	if (parent.lastChild === this) {
		parent.appendChild(i);
	} else {
		parent.insertBefore(i,this.nextSibling);
	}
};

window.Element.prototype.insertsAfter = function(is){
	var dom1 = $_create('frag');

	var parent = this.parentElement;
	if (parent.lastChild === this) {
		parent.appendChild(i);
	} else {
		parent.insertBefore(i,this.nextSibling);
	}

	for(var i in is){
		dom1.appendChild(is[i]);
	}
	this.after(dom1);
};

window.Element.prototype.childsRemove = function(){
	var dom1 = $_create('frag');
	dom1.appendChild(this);
	var flen = this.childElementCount;
	for(var f=0;f<flen;f++){
		this.removeChild(this.firstChild);
	}
};

window.Element.prototype.onlyChild = function(i){
	i.childsRemove();
};

window.Element.prototype.d_class = function (n) {
	var a = this.className.split(' ');
	if(n){
		var flen = a.length;
		for(var f=0;f<flen;f++){
			if(a[f]===n){
				return true;
			}
		}
		return false;
	} else {
		return a;
	}
};

window.Element.prototype.din_class = function (n) {
	var a = this.className.split(' ');
	if(this.d_class(n)){
		return false;
	} else {
		a.push(n);
		this.className = a.join(' ');
		return true;
	}
};

window.Element.prototype.del_class = function (n) {
	var a = this.className.split(' ');
	if(n){
		var flen = a.length;
		for(var f=0;f<flen;f++){
			if(a[f]===n){
				delete a[f];
				this.className = a.join(' ');
				return true;
			}
		}
		return false;
	} else {
		if(a.length){
			this.className = '';
			return true;
		} else {
			return false;
		}
	}
};
